﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

/// <summary>
/// 摄像机跟随目标
/// </summary>
public class CameraFlowPlayer : UnityNormalSingleton<CameraFlowPlayer> {

    Vector3 distance;
    [HideInInspector]
    public GameObject flowGameObject;

    //设置目标
    public void SetTarget (GameObject target) {
        flowGameObject = target;
        distance = transform.position - flowGameObject.transform.position;
    }

    /// <summary>
    /// 摄像机跟随移动，必须所跟随的物体的update的生命周期要在摄像机的update生命周期之前
    /// 这样就不会出现卡顿现象
    /// 所以摄像机跟随统一写在lateUpdate里面即可
    /// </summary>
    void LateUpdate() {
        if (flowGameObject != null)
        {
            transform.position = flowGameObject.transform.position + distance;
        }
	}

}
